function Service(serviceName,serviceRequest,idAlias,descAlias,dta){
    this.idService = 4;
    this.service = serviceName;
    this.callMethod = serviceRequest;
    this.idAlias=idAlias;
    this.descAlias=descAlias;
    this.dataProvider = dta||[];
    this.params = {};
}
Service.prototype.addParams = function(pParExts){
	this.params = pParExts;
	return this;
};
Service.prototype.load = function(pidDataFind,puid){	
  var idDataFind = pidDataFind||this.idService;
  var objParameters = $.extend({"puid":puid,"t":idDataFind,"s":this.callMethod,"f":"service"}, this.params);	
  objParameters["onLoad"] = function(dsa){
	     //alert("t:"+dsa.t+" dtL:"+dsa.rs.length);  
		var t = parseInt(dsa.t);
		if(t > 500){
			var dtf = $("#uid_"+t)[0]["dta"];
			var tmpservice =  ServicesSingleTone.getServiceByDesc(dtf.service);
			tmpservice.dataProvider = dsa.rs;
			dtf.setDataProviderByService(tmpservice);
		}else{
		    ServicesSingleTone.servicos[t].dataProvider = dsa.rs;
		}	  
   //ServicesSingleTone.getServiceById(parseInt(dsa.t)).dataProvider = dsa.rs;
  };
  //alert("id:"+this.idService+" s:"+this.service);
  rm.addRequest(objParameters);  
};
Service.prototype.loadOnce = function(pidDataFind,puid){	
	var idDataFind = pidDataFind||"";
	if(this.dataProvider.length==0){
		this.load(pidDataFind,puid);
	}else if(idDataFind!=""){
		var dtf = $("#uid_"+idDataFind);
		if(dtf.length>0){
			var dtfd = dtf[0]["dta"];
	  		var tmpservice =  ServicesSingleTone.getServiceByDesc(dtfd.service);
	  		//tmpservice.dataProvider = dsa.rs;
	  		dtfd.setDataProviderByService(tmpservice);
		}
	}
	
};


Service.prototype.findItemByDesc = function(desc){	
	//criar array tmp para odenar pela desc e depois realizar a pesquisa binaria
	return null;
};
Service.prototype.findItemById = function(id){	
	var ind = this.dataProvider.busca(this.idAlias,id);
        if(ind>-1){
            return this.dataProvider[ind];
        }
	return null;
};

var ServicesSingleTone = {
	servicos:[],
	addService:function(nservico){
            var tms = this.servicos.length;
            nservico.idService=tms;            
            var ind =  this.servicos.busca("service",nservico.service);
            //alert("ind:"+ind);
            if(ind<0){
            	this.servicos[tms]=nservico;
            }else if(nservico.dataProvider.length>0){
            	this.servicos[tms].dataProvider=nservico.dataProvider;
            }            
	},
	getServiceById:function(idService){
                return this.servicos[idService];
	},
	getServiceByDesc:function(descService){
            //var ind =  this.servicos.buscaBinaria("service",descService);
            var ind =  this.servicos.busca("service",descService);
            //alert("ind:"+ind);
            if(ind<0){
                return new Service("_huru","_huru","id_huru","desc_huru");
            }
            return this.servicos[ind];
	}
};